#include <bits/stdc++.h>
using namespace std;
// 定义一个结构体
struct G {
  int id;
  int start;
  int arrive;
};
G group[10001];

// 定制排序规则
bool cmp(G x, G y) {
  if (x.arrive < y.arrive || x.arrive == y.arrive && x.start < y.start ||
      x.arrive == y.arrive && x.start == y.start && x.id < y.id)
    return true;
  else
    return false;
}

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int h1, m1, h2, m2;
    char f; // 读入的":"读到f变量中
    cin >> h1 >> f >> m1 >> h2 >> f >> m2;
    group[i] = {i, h1 * 60 + m1, (h1 + h2) * 60 + m1 + m2};
  }
  sort(group + 1, group + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    cout << group[i].id << endl;
  }

  return 0;
}
